<template>
	<view class="flex-col page">
		<view class="flex-col group">
			<image src="https://diaocangdaojia.oss-cn-beijing.aliyuncs.com/adminapi/202308/202308242114330173744.jpg" class="image_1" />
			<view class="flex-col group_1">
				<view class="flex-col">
					<view class="flex-row section_1">
						<text class="text_1" style="min-width: 56px; text-align:right">姓名</text>
						<input class="text_2" type="text" v-model.trim="realname" placeholder="请输入姓名" />
					</view>
					<view class="flex-row section_2">
						<text class="text_3" style="min-width: 56px; text-align:right">性别</text>
						<u-radio-group style="margin-left: 48rpx;" v-model="radiovalue1" placement="row">
							<u-radio :customStyle="{'marginBottom': '8px'}" v-for="(item, index) in radiolist1"
								:key="index" style="margin-right: 8rpx;" activeColor=" rgb(24, 181, 103)"
								:label="item.name" :name="item.name">
							</u-radio>
						</u-radio-group>

					</view>
					<view class="section_3 flex-row">
						<text class="text_6" style="min-width: 56px; text-align:right">手机</text>
						<view>
							<input class="text_7" type="number" v-model.trim="mobile" placeholder="请输入登录手机" />
						</view>
					</view>
					<view class="section_3 flex-row" style="position: relative;">
						<text class="text_6" style="min-width: 56px; text-align:right">验证码</text>
						<view>
							<input class="text_7" type="number" v-model.trim="vcode" placeholder="请输入验证码" />
						</view>
						<view class="text_code" @tap.stop="sendMsg">{{ msg }}</view>
					</view>
					
					
					<view class="section_3 flex-row">
						<text class="text_8" style="min-width: 56px; text-align:right">年龄</text>
						<input class="text_9" type="number" v-model.trim="age" placeholder="请输入年龄" />
					</view>
					<view class="section_3 justify-between">
						<view class="flex-row">
							<text class="text_10">意向城市</text>
							<tm-pickersCity @confirm="selectedCity" btn-color="bg-gradient-deep-purple-accent"
								class="text_11">
								<text>{{ city ? city : '选择意向工作城市' }}</text>
							</tm-pickersCity>
						</view>
						<image
							src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844611732717437.png"
							class="image_5" />
					</view>
					<view class="flex-col section_4">
						<text>请上传本人近期照片</text>
						<view class="flex-col group_4" @click="upload">
							<image
								src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844659951094858.png"
								class="image_6" />
							<image
								src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844713277306992.png"
								class="image_7" />
							
							<image class="avatar" v-if="avatar" :src="avatar" mode=""></image>
						</view>
					</view>
				</view>
				<view class="flex-col items-center button" @click="submit">
					<text>申请入驻</text>
				</view>
			</view>
		</view>
		<!--城市选择-->

	</view>
</template>

<script>
	// import tmPickersCity from '@/tm-vuetify/components/tm-pickersCity/tm-pickersCity.vue';
	import { uploadImage } from '@/config/utils';
	var clear;
	export default {
		components: {
			// tmPickersCity
		},
		data() {
			return {
				radiolist1: [{
						name: '男',
						disabled: false
					},
					{
						name: '女',
						disabled: false
					}
				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				radiovalue1: '男',
				realname:'',
				mobile:'',
				city:'',
				age:"",
				avatar:'',
				isLogin:false,
				vcode: '',
				msg: '获取验证码',
				isOnclick:true
			};
		},
		onLoad() {
			this.isLogin = uni.getStorageSync('userInfo');
			if (!this.isLogin) {
				uni.showModal({
					title:'提示',
					content:'请先登录再操作',
					showCancel:false,
					success() {
						let url = window.location.href;
						uni.setStorageSync('need2url',url);
						uni.navigateTo({
							url: "/pages/user/login22"
						});
					}
				});
				return
			}

		},
		methods: {
			selectedCity(e) {
				this.city = e[0] + e[1] + e[2]
			},
			upload(){
				uni.chooseImage({
					count:1,
					success: (res) => {
						let { tempFilePaths } = res;
						let filePath = tempFilePaths[0];
						uploadImage(filePath).then(res =>{
							this.avatar = res;
						}).catch(e=>{
							uni.showToast({
								title:e,
								icon:'none'
							})
						});
					}
				})
			},
			sendMsg() {
				var that=this;
				if(!this.isOnclick){
					return;
				}
				this.isOnclick=false;
				setTimeout(()=> {
					that.isOnclick = true;
				}, 1500);
				if (this.readonly) {
					return;
				}
				if (!this.mobile) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					});
					return;
				}
				if (!this.$base.phoneRegular.test(this.mobile)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: 'none'
					});
					return;
				}
				this.$http
					.post('api/user/smsCode', {
						mobile: this.mobile,
					})
					.then(res => {
						this.getCodeState();
					});
					

			},
			//验证码按钮文字状态
			getCodeState() {
				clear && clearInterval(clear);
				const _this = this;
				this.readonly = true;
				this.msg = '60s';
				var s = 60;
				clear = setInterval(() => {
					s--;
					_this.msg = s + 's';
					if (s <= 0) {
						clearInterval(clear);
						_this.msg = '获取验证码';
						_this.readonly = false;
					}
				}, 1000);
			},
			
			submit(){
				if( !this.realname ){
					uni.showToast({
						icon:'none',
						title:'请输入技师姓名'
					});
					return;
				}
				if( !(/^1[3456789]\d{9}$/.test(this.mobile)) ){
					uni.showToast({
						icon:'none',
						title:'请输入正确格式的手机号'
					});
					return;
				}
				if( !(/^\d{6}$/.test(this.vcode)) ){
					uni.showToast({
						icon:'none',
						title:'请输入正确短信验证码'
					});
					return;
				}
				if( !this.age ){
					uni.showToast({
						icon:'none',
						title:'请输入年龄'
					});
					return;
				}
				if( !this.city ){
					uni.showToast({
						icon:'none',
						title:'请先选择意向工作城市'
					});
					return;
				}
				this.$http.post('api/user/technicianApply',{
					realname: this.realname,
					mobile: this.mobile,
					age: this.age,
					city: this.city,
					avatar: this.avatar,
					sex: this.radiovalue1 == '男' ? 1 : 2,
					vcode:this.vcode
				}).then(res =>{
					uni.showModal({
						title: '提示',
						content:res,
					});
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.page {
		background-color: #f8f8f8;
		width: 100%;
		height: 100%;
		overflow-y: auto;

		.group {
			padding-bottom: 100rpx;
			flex: 1 1 auto;
			overflow-y: auto;

			.image_1 {
				width: 100vw;
				height: 53.5vw;
			}

			.group_1 {
				margin-top: -48rpx;
				padding: 0 32rpx;
				position: relative;

				.button {
					margin-top: 24px;
					padding: 22rpx 0;
					color: rgb(255, 255, 255);
					font-size: 32rpx;
					font-weight: 500;
					line-height: 44rpx;
					white-space: nowrap;
					background-color: rgb(24, 181, 103);
					border-radius: 44rpx;
				}

				.section_1 {
					padding: 28rpx 24rpx;
					background-color: rgb(255, 255, 255);
					border-radius: 24rpx 24rpx 0px 0px;

					.text_1 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_2 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						white-space: nowrap;
						border-bottom: 1px #999 solid;
						width: 112px;
					}
				}

				.section_2 {
					padding: 24rpx 24rpx 26rpx;
					color: rgb(0, 0, 0);
					font-size: 28rpx;
					font-weight: 500;
					line-height: 40rpx;
					white-space: nowrap;
					background-color: rgb(255, 255, 255);

					.text_3 {
						margin-top: 4rpx;
					}

					.image_2 {
						width: 44rpx;
						height: 44rpx;
					}

					.image_3 {
						margin-left: 48rpx;
					}

					.text_4 {
						margin-left: 4rpx;
						margin-top: 4rpx;
					}

					.image_4 {
						margin-left: 40rpx;
					}

					.text_5 {
						margin-left: 4rpx;
						margin-bottom: 4rpx;
					}
				}

				.section_3 {
					padding: 28rpx 24rpx;
					background-color: rgb(255, 255, 255);

					.text_6 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_7 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						white-space: nowrap;
						width: 112px;
						
						border-bottom: 1px #999 solid;
					}
					.text_code{
						color: rgb(24, 181, 103);
						font-size: 14px;
						position: absolute;
						right: 8px;
					}

					.text_8 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_9 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						white-space: nowrap;
						border-bottom: 1px #999 solid;
						width: 112px;
					}

					.image_5 {
						margin-bottom: 6rpx;
						width: 32rpx;
						height: 32rpx;
					}

					.text_10 {
						color: rgb(0, 0, 0);
						font-size: 28rpx;
						font-weight: 500;
						line-height: 40rpx;
						white-space: nowrap;
					}

					.text_11 {
						margin-left: 48rpx;
						color: rgb(153, 153, 153);
						font-size: 28rpx;
						line-height: 40rpx;
						white-space: nowrap;
						border-bottom: 1px #999 solid;
					}
				}

				.section_3>text{
					min-width: 56px;
				}

				.section_4 {
					padding: 28rpx 23rpx 31rpx;
					color: rgb(0, 0, 0);
					font-size: 28rpx;
					font-weight: 500;
					line-height: 40rpx;
					white-space: nowrap;
					background-color: rgb(255, 255, 255);
					border-radius: 0px 0px 24rpx 24rpx;

					.group_4 {
						margin-top: 31rpx;
						padding: 71rpx 0 71rpx;
						position: relative;

						.image_6 {
							margin-left: 71rpx;
							width: 56rpx;
							height: 56rpx;
						}

						.image_7 {
							border-radius: 24rpx;
							width: 198rpx;
							height: 198rpx;
							position: absolute;
							left: 0;
							top: 0;
						}
						.avatar{
							border-radius: 24rpx;
							position: absolute;
							width: 198rpx;
							height: 198rpx;
							position: absolute;
							left: 0;
							top: 0;
							z-index: 9;
						}
					}
				}
			}
		}
	}
</style>
